package com.example.springboot.controller.admin;

import com.example.springboot.model.enums.ResultCodeEnum;
import com.example.springboot.model.form.Result;
import com.example.springboot.model.req.admin.EnshrineReq;
import com.example.springboot.model.req.admin.LikeReq;
import com.example.springboot.model.req.admin.MaterialReq;
import com.example.springboot.service.admin.MaterialService;
import com.example.springboot.utils.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zf
 * @version 1.0
 * @ClassName MaterialController
 * @素材表
 * @since 2021-03-17
 */
@RestController
@RequestMapping("/material")
public class MaterialController {

    @Resource
    private MaterialService service;

    /**
     * @param req
     * @Description: 列表
     */
    @PostMapping("/list")
    public Result list(MaterialReq req) {
        return service.getPage(req);
    }

    /**
     * @param req
     * @Description: 新增修改
     */
    @PostMapping("/save")
    public Result save(MaterialReq req) {
        return service.addInfo(req);
    }

    /**
     * @param id
     * @Description: 详情
     */
    @PostMapping("/info")
    public Result getById(Integer id) {
        Assert.isNull(id, ResultCodeEnum.CLIENT_PARAM_ERROR);
        return service.getInfo(id);
    }

    /**
     * @param ids
     * @Description: 批量删除
     */
    @PostMapping("/deleteIds")
    public Result deleteInfos(String ids) {
        Assert.isNull(ids, ResultCodeEnum.CLIENT_PARAM_ERROR);
        return service.deleteInfos(ids);
    }

    /**
     * @Description:  添加收藏
     */
    @PostMapping("/enshrineSave")
    public Result enshrineSave(EnshrineReq req) {
        return Result.buildSuccess(service.enshrineSave(req));
    }

    /**
     * @Description:  取消收藏
     */
    @PostMapping("/enshrineCancel")
    public Result enshrineCancel(EnshrineReq req) {
        return Result.buildSuccess(service.enshrineCancel(req));
    }

    /**
     * @Description:  点赞
     */
    @PostMapping("/likeSave")
    public Result likeSave(LikeReq req) {
        return Result.buildSuccess(service.likeSave(req));
    }

    /**
     * @Description:  取消点赞
     */
    @PostMapping("/likeCancel")
    public Result likeCancel(LikeReq req) {
        return Result.buildSuccess(service.likeCancel(req));
    }
}